---@class UIConfirm : UIBase
UIConfirm = UIBase.New(PanelResNames.UIConfirm)
local t = UIConfirm

function t.Init(des,subDes,sureCallback,cancelCallback,tb,sureText,cancelText,title,itemId)
    t.des = des
    t.subDes = subDes
    t.sureCallback = sureCallback
    t.cancelCallback = cancelCallback
    --t.callbackTB = tb --请勿使用
    -- TODO 本地文本需要放置在本地表中
    t.sureText = sureText or "确定"
    t.cancelText = cancelText or "取消"
    t.title = title
    t.showItemID = itemId or false
    UIBase.Init(t)
end

function t:OnCreate()
    self.desText = self:GetChild("ConfirmTips")
    self.desText.UBBEnabled = true;
    self.subDesText = self:GetChild("SmallTips")
    self.ctrlSub = self:GetController("ctrlSub")
    self.ctrlShowItem = self:GetController("item")
    self.btnCancel = self:GetChild("btnCancel")
    self.btnSure = self:GetChild("btnSure")
    self.btnFullClose = self:GetChild("BgClose")
    self.titleText = self:GetChild("Bg/title")
    self.itemIcon = self:GetChild("Com_Res")
    self.itemCount = self.itemIcon:GetChild("title")
    self:RegisterOnClick(self.btnCancel,self.ClickCancel)
    self:RegisterOnClick(self.btnSure,self.ClickSure)
    self:RegisterOnClick(self.btnFullClose,self.ClickCancel)
end

function t:OnEnable()
    self:Refresh()
end

function t:OnDisable()
end
function t:OnDestroy()
end

function t:Refresh()
    self.desText.text = t.des
    if t.subDes == "" then
        self.ctrlSub.selectedIndex = 0
    else
        self.subDesText.text = t.subDes
        self.ctrlSub.selectedIndex = 1
    end
    self.ctrlShowItem.selectedIndex = 0
    if t.showItemID then
        self.ctrlShowItem.selectedIndex = 1
        local itemNum = logicMgr.ItemManager.getItemCountbyModelId(t.showItemID);
        local singleItemConfig = logicMgr.ItemManager.getItemConstDatabyModelId(t.showItemID);
        self.itemIcon.icon = "ui://ItemAtlas/" .. singleItemConfig["icon"];
        self.itemCount.text = tostring(itemNum);
    end

    self.btnSure.text = self.sureText
    self.btnCancel.text = self.cancelText
    if t.title then
        self.titleText.text = t.title
    end
end

function t:ClickCancel()
    local tb = t.callbackTB
    local callback = t.cancelCallback
    t.cancelCallback = nil
    t.callbackTB = nil
    if callback then
        if tb then
            callback(tb)
        else
            callback()
        end
    end
    closeUI(PanelResNames.UIConfirm)
end
function t:ClickSure()
    local tb = t.callbackTB
    local callback = t.sureCallback
    t.sureCallback = nil
    t.callbackTB = nil
    if callback then
        if tb then
            callback(tb)
        else
            callback()
        end
    end
    closeUI(PanelResNames.UIConfirm)
end

return t